# 逗你玩——加强版本
from tkinter import *
from random import *
import time
import threading

root = Tk()
root.title("逗你玩")

def test(event):
    global rand_num
    if (event.widget == button_list[rand_num]):
        info_list[rand_num].set("Null")
		
        a = rand_num
        while (rand_num == a):
            rand_num = randint(0, 8)
        info_list[rand_num].set("Good Luck")
    else:
        time.sleep(0.2)
        info_list[rand_num].set("Null")
        rand_num = randint(0, 8)
        info_list[rand_num].set("Good Luck")

info_list = []
button_list = []

for i in range(9):
    var = StringVar()
    var.set("Null")
    info_list.append(var)

rand_num = randint(0, 8)
info_list[rand_num].set("Good Luck")

j = -1
for i in range(9):
    if (i % 3 == 0):
        j += 1
    b = Button(root, height = 6, width = 20, textvariable = info_list[i])
    b.grid(row = j, column = i % 3)
    b.bind("<Button-1>", test)
    button_list.append(b)


root.mainloop()